package com.hermes.biz.cdn.qn;

import org.apache.log4j.Logger;
import org.json.JSONException;

import com.hermes.biz.dao.item.impl.CategorysDAOImpl;
import com.qiniu.api.auth.AuthException;
import com.qiniu.api.auth.digest.Mac;
import com.qiniu.api.io.IoApi;
import com.qiniu.api.io.PutExtra;
import com.qiniu.api.io.PutRet;
import com.qiniu.api.rs.PutPolicy;

/**
 * 此demo已经成功上传到qiniu云存储
 * @author cardoo
 *
 */
public class CDNFileOp {
	private  Logger log = Logger.getLogger(CDNFileOp.class);
	public  void upLoadFile(String ak,String sk,String bucketName,String key,String localFile){
		
		Mac mac = new Mac(ak,sk);
		String uptoken;
		PutPolicy putPolicy = new PutPolicy(bucketName);
		try {
			uptoken = putPolicy.token(mac);
			PutExtra extra = new PutExtra();
			PutRet ret = IoApi.putFile(uptoken, key, localFile, extra);
			System.out.println(ret.getResponse());
			System.out.println(ret.getException());
		} catch (AuthException e) {
			log.error("AuthException , ak:"+ak);
		} catch (JSONException e) {
			log.error("JSONException , ak:"+ak);
		}
	}
	
	public static void main(String[] args){
		//upLoadFile(CDNConstant.CONFIG_AK,CDNConstant.CONFIG_SK,"cardoo","haldlfd","C:\\Kalo.jpg");
	}
}
